import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useAuthorizationStore = defineStore(
  'authorization',
  () => {
    const token = ref<string>('')

    function signIn(v: string) {
      token.value = v
    }

    function signOut() {
      token.value = ''
    }

    function isAuthenticated() {
      return token.value !== ''
    }

    return { token, signIn, signOut, isAuthenticated }
  },
  {
    persist: true
  }
)

export function isAuthenticated() {
  return useAuthorizationStore().isAuthenticated()
}
